import {
  exportUrl,
  downloadTemplateUrl,
  getWarningStatusList,
} from "@/api/warn/mesWarnReport";
import { getAllList } from '@/api/baseequipment/commonBaseEquipment'
import { exportExcel } from "@/utils/judge";

import store from "@/store";

import {
  getLineCodeList,
  getWorkCellCodeList,
} from "@/api/employee/mesUserExtend";

// 列表头按钮配置
export const operateList = [
  {
    name: $i18n.t("common.export"),
    type: "primary",
    icon: "el-icon-download",
    handleName: "export", //点击时返回的标识
    url: exportUrl,
    //auth: "auth:operlog:export", //权限字段
  },
];
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("mesWarnReport.previewImg"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "previewImg", //点击时返回的标识
    show: (row) => {
      return !!row.handlePath;
    },
  },
];
// 搜索条件配置
export const searchConfig = {
  inline: true,
  formDesc: {
    workshopCode: {
      type: "select",
      label: $i18n.t("common.workshopName"),
      attrs: {
        filterable: true,
      },
      prop: {
        value: "modelingCode",
        text: "modelingName",
      },
      options: async (data) => {
        const params = {
          modelingCode: store.getters.factoryCode,
          modelingType: '0',
          level: 4,
        };
        const list = await getLineCodeList(params);
        return list.data.result;
      },
    },
    lineCode: {
      type: "select",
      label: $i18n.t("common.line"),
      optionsLinkageFields: ["workshopCode"],
      isReloadOptions: true,
      attrs: {
        filterable: true,
      },
      prop: {
        value: "modelingCode",
        text: "modelingName",
      },
      options: async (data) => {
        if (data.workshopCode) {
          const list = await getLineCodeList({
            modelingCode: data.workshopCode,
          });
          return list.data.result;
        } else {
          return [];
        }
        // const params = {
        //   modelingCode: this.$store.getters.factoryCode,
        //   level: 5,
        // };
        // const list = await getLineCodeList(params);
        // return list.data.result;
      },
    },
    stationCode: {
      type: "select",
      label: $i18n.t("common.workCell"),
      optionsLinkageFields: ["lineCode"],
      isReloadOptions: true,
      attrs: {
        filterable: true,
      },
      prop: {
        value: "modelingCode",
        text: "modelingName",
      },
      options: async (data) => {
        if (data.lineCode) {
          const list = await getWorkCellCodeList({
            modelingCode: data.lineCode,
          });
          return list.data.result;
        } else {
          return [];
        }
      },
    },
    createTime: {
      type: "datetimerange",
      label: $i18n.t("common.createTime"),
      attrs: {
        valueFormat: "yyyy-MM-dd HH:mm:ss",
        searchArrKey: ["createTimeMin", "createTimeMax"],
      },
    },
    equipmentCode: {
      type: "select",
      label: $i18n.t("mesWarnReport.equipmentName"),
      attrs: {
        filterable: true,
      },
      prop: {
        value: "equipmentCode",
        text: "equipmentName",
      },
      options: async (data) => {
        const list = await getAllList();
        return list.data.result;
      },
    },
    warnStatus: {
      type: "select",
      label: $i18n.t("mesWarnReport.warnStatus"),
      prop: {
        value: "value",
        text: "description",
      },
      options: async (data) => {
        const list = await getWarningStatusList();
        return list.data.result;
      },
    },
  },
};
// 新增/删除表单配置
export const formMixin = {
  data() {
    return {
      formDescDialog: {
        span: 24,
        disabled: false,
        isShowSubmitBtn: true,
        formDesc: {
          warningCode: {
            type: "input",
            label: $i18n.t("mesWarnReport.warningCode"),
            layout: 12,
            required: false,
          },
          warningName: {
            type: "input",
            label: $i18n.t("mesWarnReport.warningName"),
            layout: 12,
            required: false,
          },
          warningType: {
            type: "input",
            label: $i18n.t("mesWarnReport.warningType"),
            layout: 12,
            required: false,
          },
          workshopName: {
            type: "input",
            label: $i18n.t("common.workshopName"),
            layout: 12,
            required: false,
          },
          workshopCode: {
            type: "input",
            label: $i18n.t("common.workshopCode"),
            layout: 12,
            required: false,
          },
          lineCode: {
            type: "input",
            label: $i18n.t("common.lineCode"),
            layout: 12,
            required: false,
          },
          lineName: {
            type: "input",
            label: $i18n.t("common.lineName"),
            layout: 12,
            required: false,
          },
          factoryCode: {
            type: "input",
            label: $i18n.t("common.factoryCode"),
            layout: 12,
            required: false,
          },
          warningStatus: {
            type: "select",
            label: $i18n.t("mesWarnReport.warningStatus"),
            layout: 12,
            required: false,
            prop: {
              value: "value",
              text: "description",
            },
            options: async (data) => {
              const list = await getWarningStatusList();
              return list.data.result;
            },
          },
          beginDate: {
            type: "date",
            label: $i18n.t("mesWarnReport.beginDate"),
            layout: 12,
            required: false,
            attrs: {
              valueFormat: "yyyy-MM-dd",
            },
            on: {
              change: (val) => {
                this.handleBeginDate(val);
              },
            },
          },
          endDate: {
            type: "date",
            label: $i18n.t("mesWarnReport.endDate"),
            layout: 12,
            required: false,
            attrs: {
              valueFormat: "yyyy-MM-dd",
            },
            on: {
              change: (val) => {
                this.handleEndDate(val);
              },
            },
          },
          remark: {
            type: "input",
            label: $i18n.t("common.remark"),
            layout: 12,
            required: false,
          },
        },
      },
    };
  },
};

//导入数据
export const importFormDescDialog = {
  span: 24,
  disabled: false,
  isShowSubmitBtn: true,
  formDesc: {
    model: {
      type: "button",
      label:"",// $i18n.t("mesWarnReport.model"),
      layout: 24,
      required: false,
      title: $i18n.t("common.downloadTemplate"),
      style: {
        color: "#1867c0",
        fontSize: "14px",
      },
      on: {
        click: () => {
          exportExcel(downloadTemplateUrl);
        },
      },
    },
    file: {
      type: "input",
      label: $i18n.t("common.chooseFile"),
      layout: 24,
      // required: true,
    },
  },
};
